package com.example.peanutsubway.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionBindingEvent;

@WebListener()
public class ProjectPathListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 获取作用域对象
        ServletContext servletContext = sce.getServletContext();
        // 获取项目发布的路径
        String contextPath = servletContext.getContextPath();
        // 将路劲存储在作用域中
        servletContext.setAttribute("path", contextPath);
    }
}
